<?php

namespace App\Http\Validate\Third\Xiaoke;

use App\Http\Validate\AbstractBaseValidate;
use Illuminate\Support\MessageBag;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class XiaokeValidate extends AbstractBaseValidate
{
    function getRules(): array
    {
        // TODO: Implement getRules() method.
        return [];
    }

    function getAttributes(): array
    {
        // TODO: Implement getAttributes() method.
        return [];
    }

    function registerValidateRules(): void
    {
        // TODO: Implement registerValidateRules() method.
    }

    function getMessages(): array
    {
        // TODO: Implement getMessages() method.
        return [];
    }

    /**
     * 回调通知校验
     *
     * @param array $params
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function notifyValidate(array $params)
    {
        return self::getInstance()->validate(
            [
                "kfBusinessType",
                "id",
                "business_id",
                "event",
                "model",
                "msg_body",
                "public_account_id",
                "version",
                "topic"
            ],
            $params,
            [
                "kfBusinessType"    => [
                    "required",
                    "string",
                    Rule::in(["clue", "customer", "clueToCustomer", "clueChangeOwner", "customerUpdate"])
                ],
                "id"                => "required|string",
                "business_id"       => "required|int",
                "event"             => "required|string",
//                "model"             => "required|string",
                "msg_body"          => Rule::when(
                    $params["kfBusinessType"] == "clueChangeOwner",
                    "required|array",
                    "required|string"
                ),
                "public_account_id" => Rule::when(
                    $params["kfBusinessType"] == "clueChangeOwner",
                    "required|int",
                    "required|string"
                ),
//                "version"           => "required|string",
                "topic"             => "required|string",
            ]
        );
    }
}
